package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqAppDisable;
import com.wtwd.campus.entity.MqAppDisableTime;
import com.wtwd.campus.service.InjectFeignService;

import java.util.ArrayList;

/**
 * @author mjy
 * @date 2022/12/15
 * @description
 */
public class SetAppDisableReceiver implements Receiver {

//    *TJ,IMEI,APPDISABLE,seq,package,switch,groupNum,stratTime,endTime,cycle#


    @Override
    public String parseMessage(String data) {
        String[] split = data.split(",");
        String imei = split[1];
        String commandNumber = split[3];
        String packageName = split[4];
        String flag = split[5];
        String date = split[split.length - 2];
        String deviceStatus = split[split.length - 1];
        int groupNum = Integer.valueOf(split[6]);
        ArrayList<MqAppDisableTime> mqAppDisableTimes = new ArrayList<>();
        for (int i = 1; i <= groupNum; i++) {
            MqAppDisableTime mqAppDisableTime = new MqAppDisableTime();
            mqAppDisableTime.setStartTime(split[6 + 3 * (i - 1) + i]);
            mqAppDisableTime.setEndTime(split[7 + 3 * (i - 1) + i]);
            mqAppDisableTime.setCycle(split[8 + 3 * (i - 1) + i]);
            mqAppDisableTime.setActivation(Integer.valueOf(split[9 + 3 * (i - 1) + i]));
            mqAppDisableTimes.add(mqAppDisableTime);
        }
        MqAppDisable mqAppDisable = new MqAppDisable();
        mqAppDisable.setImei(imei);
        mqAppDisable.setCommandNumber(commandNumber);
        mqAppDisable.setPackageName(packageName);
        mqAppDisable.setFlag(Integer.valueOf(flag));
        mqAppDisable.setGroupNum(groupNum);
        mqAppDisable.setDeviceDate(date);
        mqAppDisable.setDeviceTime(commandNumber);
        mqAppDisable.setDeviceStatus(deviceStatus);
        mqAppDisable.setMqAppDisableTime(mqAppDisableTimes);
        InjectFeignService.getIrmFeignClientService().setAppDisableReceiver(mqAppDisable);
        return imei;
    }
}
